package org.wz.complex.work.kit.encrypt;


import cn.hutool.core.lang.Dict;
import cn.hutool.crypto.SecureUtil;


import cn.hutool.jwt.JWTUtil;
import org.wz.complex.work.entity.auth.sysinfo.SysinfoUser;

public interface UserKit {

    public static String TOKEN_KEY = "E38A6870127AF244C92938795A42A2BD2708364989E2E809D15496D15F8DA591";

    public static String encrypt(SysinfoUser user) {
        StringBuffer sb = new StringBuffer();
        sb.append("#start=" + "pc" + "#&");
        sb.append("id=" + user.getId() + "&");
        sb.append("username=" + user.getUsername() + "&");
        sb.append("password=" + user.getPassword() + "&");
        sb.append("salt=" + user.getSalt() + "&");
        sb.append("time=" + user.getTime() + "&");
        sb.append("roleId=" + user.getRoleId() + "&");
        sb.append("#tokenKey=" + TOKEN_KEY + "&");
        String line = sb.toString();
        return SecureUtil.sha256(line).toUpperCase();
    }


    public static String token(String username, Long userId) {
        Dict set = Dict.create()
                .set("userId", userId)
                .set("username", username)
                .set("tokenKey", SecureUtil.sha256(TOKEN_KEY + "_" + System.currentTimeMillis()))
                .set("time", System.currentTimeMillis())
                .set("valid", true);

        return JWTUtil.createToken(set, TOKEN_KEY.getBytes());
    }



    public static void main43433443(String[] args) {
        String s = SaltKit.get8Len();
        System.out.println("salt: " + s);
        long now = System.currentTimeMillis();
        System.out.println("now: " + now);
        SysinfoUser build = SysinfoUser.builder()
                .id(1L)
                .username("")
                .password("")
                .roleId(1L)
                .salt(s)
                .time(String.valueOf(now))
                .build();
        String encrypt = encrypt(build);
        System.out.println("encrypt: " + encrypt);

    }






















}
